package com.cn.wx.servlet.backnews;

import com.cn.wx.model.NewsModel;
import com.cn.wx.model.UserModel;
import com.cn.wx.service.LoginService;
import com.cn.wx.service.NewsService;
import com.cn.wx.util.Page;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/newsFindAll")
public class NewsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        NewsService newsService = new NewsService();
        Integer count = newsService.count("");
        Map<String, Object> map = Page.getPageNum(req, "type", "dangqianye", "pageSize", count);
        List<NewsModel> list = newsService.getAll(Integer.parseInt(map.get("pageSize").toString()), Integer.parseInt(map.get("dangqianye").toString()));
        ServletContext context = req.getServletContext();
        req.setAttribute("map", map);
        req.setAttribute("list", list);
        context.setAttribute("aa", "1");//对aa进行赋值
        context.setAttribute("aa", "2");//对aa进行修改
        context.removeAttribute("aa");//对aa进行删除
        req.setAttribute("patha", req.getAttribute("path"));
        req.getRequestDispatcher("/back/newsmanage.jsp").forward(req, resp);//页面转发
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
